1669D - Colorful Stamp - CodeForces Solution


implementation *1100

Please click on ads to support us..

Python Code:

import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353
for _ in range(I()):
    n=I();s=S();f=0
    if n==1:
        if s[0]=='W':print("YES")
        else:print("NO")
        continue
    l=list(s.split('W'))
    for i in l:
        if len(i)>0 and (i=='R'*len(i) or i=='B'*len(i)):f=1;break
    print("NO" if f else "YES")

C++ Code:

// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        string s;cin>>s;
        int c=0,r=0,b=0;
        string a;
        
          for(int i=0;i<n;i++){
            if(s[i]=='W'){
                if(r==0 && b==0 || r>0 && b>0)r=0,b=0,c=0;
                else{
                    a="N";
                    cout<<"No"<<endl;
                    break;
                }
            }
            if(s[i]=='R')r++;
            if(s[i]=='B')b++;
            c++;
           }
        if(a!="N"){
            if(r>0 && b>0 || r==0 && b==0)
            cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
            
        
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

439A - Devu the Singer and Churu the Joker
1323A - Even Subset Sum Problem
1095A - Repeating Cipher
630F - Selection of Personnel
630K - Indivisibility
20B - Equation
600B - Queries about less or equal elements
1015A - Points in Segments
1593B - Make it Divisible by 25
680C - Bear and Prime 100
1300A - Non-zero
1475E - Advertising Agency
1345B - Card Constructions
1077B - Disturbed People
653A - Bear and Three Balls
794A - Bank Robbery
157A - Game Outcome
3B - Lorry
1392A - Omkar and Password
489A - SwapSort
932A - Palindromic Supersequence
433A - Kitahara Haruki's Gift
672A - Summer Camp
1277A - Happy Birthday Polycarp
577A - Multiplication Table
817C - Really Big Numbers
1355A - Sequence with Digits
977B - Two-gram
993A - Two Squares
1659D - Reverse Sort Sum